﻿// copyright jyz.2024

#pragma once

#include "CoreMinimal.h"
#include "AuraInputConfig.h"
#include "EnhancedInputComponent.h"
#include "AuraEnhancedInputComponent.generated.h"


UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class AURARPGDEMO_API UAuraEnhancedInputComponent : public UEnhancedInputComponent
{
	GENERATED_BODY()

public:
	template<class UseClass,typename PressedFuncType,typename ReleaseFuncType,typename HeldFuncType>
	void BindAbilityActions(const UAuraInputConfig* InputConfig,UseClass* Object,PressedFuncType PressedFunc,ReleaseFuncType ReleaseFunc,HeldFuncType HeldFunc)
	{
		check(InputConfig);
		for(const FAuraInputAction& Action: InputConfig->AbilityInputActions)
		{
			if(Action.InputAction&&Action.InputTag.IsValid())
			{
				if(PressedFunc)
				{
					BindAction(Action.InputAction,ETriggerEvent::Started,Object,PressedFunc,Action.InputTag);
				}
				if(ReleaseFunc)
				{
					BindAction(Action.InputAction,ETriggerEvent::Completed,Object,ReleaseFunc,Action.InputTag);
				}
				if(HeldFunc)
				{
					BindAction(Action.InputAction,ETriggerEvent::Triggered,Object,HeldFunc,Action.InputTag);
				}
			}
		}
	}
	// Sets default values for this component's properties
	UAuraEnhancedInputComponent();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};
